/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.google.common.base.Strings;
/*     */ import com.zimbra.client.ZFolder;
/*     */ import com.zimbra.client.ZMailbox;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestFolders
/*     */   extends TestCase
/*     */ {
/*  30 */   private static String USER_NAME = "user1";
/*  31 */   private static String NAME_PREFIX = "TestFolders";
/*     */   
/*     */   private String mOriginalEmptyFolderBatchSize;
/*     */   
/*     */   protected void setUp()
/*     */     throws Exception
/*     */   {
/*  38 */     cleanUp();
/*  39 */     this.mOriginalEmptyFolderBatchSize = TestUtil.getServerAttr("zimbraMailEmptyFolderBatchSize");
/*     */   }
/*     */   
/*     */   public void testEmptyLargeFolder()
/*     */     throws Exception
/*     */   {
/*  45 */     TestUtil.setServerAttr("zimbraMailEmptyFolderBatchSize", Integer.toString(3));
/*     */     
/*     */ 
/*  48 */     String parentPath = "/" + NAME_PREFIX + "-parent";
/*  49 */     ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
/*  50 */     ZFolder parent = TestUtil.createFolder(mbox, parentPath);
/*  51 */     ZFolder child = TestUtil.createFolder(mbox, parent.getId(), "child");
/*     */     
/*     */ 
/*  54 */     for (int i = 1; i <= 5; i++) {
/*  55 */       TestUtil.addMessage(mbox, NAME_PREFIX + " parent " + i, parent.getId());
/*  56 */       TestUtil.addMessage(mbox, NAME_PREFIX + " child " + i, child.getId());
/*     */     }
/*  58 */     mbox.noOp();
/*  59 */     assertEquals(5, parent.getMessageCount());
/*  60 */     assertEquals(5, child.getMessageCount());
/*     */     
/*     */ 
/*  63 */     mbox.emptyFolder(parent.getId(), false);
/*  64 */     mbox.noOp();
/*  65 */     assertEquals(0, parent.getMessageCount());
/*  66 */     assertEquals(5, child.getMessageCount());
/*     */     
/*     */ 
/*  69 */     for (int i = 6; i <= 10; i++) {
/*  70 */       TestUtil.addMessage(mbox, NAME_PREFIX + " parent " + i, parent.getId());
/*     */     }
/*  72 */     mbox.noOp();
/*  73 */     assertEquals(5, parent.getMessageCount());
/*  74 */     assertEquals(5, child.getMessageCount());
/*     */     
/*     */ 
/*  77 */     String childPath = child.getPath();
/*  78 */     assertNotNull(mbox.getFolderByPath(childPath));
/*  79 */     mbox.emptyFolder(parent.getId(), true);
/*  80 */     mbox.noOp();
/*  81 */     assertEquals(0, parent.getMessageCount());
/*  82 */     assertNull(mbox.getFolderByPath(childPath));
/*     */   }
/*     */   
/*     */   public void testCreateManyFolders() throws Exception
/*     */   {
/*  87 */     boolean skip = true;
/*  88 */     if (skip) {
/*  89 */       return;
/*     */     }
/*     */     
/*  92 */     ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
/*  93 */     String parentPath = "/" + NAME_PREFIX + "-parent";
/*     */     
/*  95 */     ZFolder parent = TestUtil.createFolder(mbox, parentPath);
/*  96 */     int max = 10000;
/*  97 */     int pad = (int)Math.log10(max) + 1;
/*  98 */     long totalTime = 0L;
/*     */     
/* 100 */     long maxTime = 0L;
/* 101 */     for (int i = 0; i < max; i++) {
/* 102 */       long start = System.currentTimeMillis();
/* 103 */       TestUtil.createFolder(mbox, parent.getId(), "child" + Strings.padStart(new StringBuilder().append(i).append("").toString(), pad, '0'));
/* 104 */       long end = System.currentTimeMillis();
/* 105 */       long elapsed = end - start;
/* 106 */       totalTime += elapsed;
/* 107 */       if (elapsed > maxTime) {
/* 108 */         maxTime = elapsed;
/* 109 */         ZimbraLog.mailbox.info("FOLDER TIME new max time %dms at index %d", new Object[] { Long.valueOf(maxTime), Integer.valueOf(i) });
/*     */       }
/* 111 */       if ((i > 0) && ((i % 100 == 0) || (i == max - 1))) {
/* 112 */         double avgTime = totalTime * 1.0D / (i * 1.0D);
/* 113 */         ZimbraLog.mailbox.info("FOLDER TIME average after %d = %dms", new Object[] { Integer.valueOf(i), Long.valueOf(Math.round(avgTime)) });
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   private void cleanUp() throws Exception
/*     */   {
/* 120 */     TestUtil.deleteTestData(USER_NAME, NAME_PREFIX);
/* 121 */     ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
/* 122 */     ZFolder f = mbox.getFolderByPath("/f1");
/* 123 */     if (f != null) {
/* 124 */       mbox.deleteFolder(f.getId());
/*     */     }
/*     */   }
/*     */   
/*     */   protected void tearDown() throws Exception
/*     */   {
/* 130 */     cleanUp();
/* 131 */     TestUtil.setServerAttr("zimbraMailEmptyFolderBatchSize", this.mOriginalEmptyFolderBatchSize);
/*     */   }
/*     */   
/*     */   public static void main(String[] args) throws Exception
/*     */   {
/* 136 */     TestUtil.cliSetup();
/* 137 */     TestUtil.runTest(TestFolders.class);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestFolders.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */